#ifndef MEMROY_BLOCK_HEADER_
#define MEMROY_BLOCK_HEADER_
#include "CacheObject.h"

class MemoryBlock : public CacheObject<MemoryBlock>
{
public:
	MemoryBlock();
	MemoryBlock(char* _buf,int _len);
	MemoryBlock(int _len);
	MemoryBlock(const MemoryBlock& block);
	template<typename T>
	bool write(T& obj)
	{
		if(sizeof(obj)+ptr>len)
		{
			return false;
		}
		memcpy(buf+ptr,&obj,sizeof(obj));
		ptr+=sizeof(obj);
		return true;
	}
	const char* getBuf() const
	{
		return buf;
	}
	int getLen() const
	{
		return len;
	}
	bool copy(const char* _buf,int _len);
public:
	static void testMemoryBlock();
private:
	char* buf;
	unsigned int len;
	unsigned int ptr;
};

#endif